package com.water_work_form.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.water_work_form.entity.BasicChlorophyll;
import com.water_work_form.result.Result;
import com.water_work_form.result.ResultCodeEnum;
import com.water_work_form.result.ResultUtil;
import com.water_work_form.service.BasicChlorophyllService;
import com.water_work_form.util.RandomIdUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 基础表——叶绿素 前端控制器
 * </p>
 *
 * @author xuke
 * @since 2023-08-01
 */
@Api(tags = {"叶绿素 前端控制器"})
@RestController
@RequestMapping("/basic-chlorophyll")
public class BasicChlorophyllController {

    @Autowired
    BasicChlorophyllService basicChlorophyllService;

    /**
     * 叶绿素 新增项目
     * @param basicChlorophyll 新项目
     * @return result code 0成功
     */
    @ApiOperation("新增")
    @PostMapping("/add")
    public Result addBasicChlorophyll(@RequestBody BasicChlorophyll basicChlorophyll){
        basicChlorophyll.setId(RandomIdUtil.createRandomId());
        basicChlorophyllService.save(basicChlorophyll);
        return ResultUtil.success(ResultCodeEnum.SUCCESS, basicChlorophyll);
    }

    /**
     * 叶绿素 查看（分页）
     * @param name 项目
     * @param current 分页 当前页
     * @param size 分页 每页数据量
     * @return 返回当页数据
     */
    @ApiOperation("查看(分页)")
    @GetMapping("/pageList")
    public Result listBasicChlorophyll(@RequestParam("name") String name, @RequestParam("current") Integer current,
                                       @RequestParam("size") Integer size){
        IPage<BasicChlorophyll> page = basicChlorophyllService.listChlorophyll(name, current, size);
        return ResultUtil.success(ResultCodeEnum.SUCCESS, page);
    }

    /**
     * 叶绿素 根据id删除项目
     * @param id 需删除的项目id
     * @return result code 0成功
     */
    @ApiOperation("删除")
    @DeleteMapping("/delete")
    public Result deleteBasicChlorophyll(@RequestParam("id") Long id){
        basicChlorophyllService.removeById(id);
        return ResultUtil.success(ResultCodeEnum.SUCCESS);
    }

    /**
     * 叶绿素 更新项目
     * @param basicChlorophyll 更新的项目
     * @return result code 0成功
     */
    @ApiOperation("更新")
    @PostMapping("/update")
    public Result updateBasicChlorophyll(@RequestBody BasicChlorophyll basicChlorophyll){
        basicChlorophyllService.updateById(basicChlorophyll);
        return ResultUtil.success(ResultCodeEnum.SUCCESS);
    }

}

